package com.example.mobile2121606109ycg0429homework1;

import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {

    private Button btnMain191;
    private Button btnMain192;
    private RecyclerView tvMainSdtItem;
    private List<Student> list191;
    private List<Student> list192;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
        initDate191();
        initDate192();

        tvMainSdtItem.setLayoutManager(new LinearLayoutManager((Context) this));
        btnMain191.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                StudentRVAdapter adapter = new StudentRVAdapter(list191);
                tvMainSdtItem.setAdapter(adapter);
            }
        });

        btnMain192.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                StudentRVAdapter adapter = new StudentRVAdapter(list192);
                tvMainSdtItem.setAdapter(adapter);
            }
        });


    }

    private void initDate191() {
        list191 = new ArrayList<>();
        list191.add(new Student("1910605001","小王","女","广东佛山"));
        list191.add(new Student("1910605002","小杨","男","广东阳江"));
        list191.add(new Student("1910605003","小吴","女","广东佛山"));
        list191.add(new Student("1910605004","小梁","男","广东广州"));
        list191.add(new Student("1910605005","小潘","女","广东佛山"));
        list191.add(new Student("1910605006","小杨","男","广东深圳"));
        list191.add(new Student("1910605007","小朱","男","广东佛山"));
    }

    private void initDate192(){
        list192 = new ArrayList<>();
        list192.add(new Student("1910605001","小黄","女","广东清远"));
        list192.add(new Student("1910605002","小陈","男","广东惠州"));
        list192.add(new Student("1910605003","小张","女","广东佛山"));
        list192.add(new Student("1910605004","小谢","男","广东云浮"));
        list192.add(new Student("1910605005","小丁","女","广东佛山"));
        list192.add(new Student("1910605006","小欧","男","广东珠海"));
        list192.add(new Student("1910605007","小莫","男","广东佛山"));
    }

    private void initView() {
        btnMain191 = (Button) findViewById(R.id.btnMain191);
        btnMain192 = (Button) findViewById(R.id.btnMain192);
        tvMainSdtItem = (RecyclerView) findViewById(R.id.tvMainSdtItem);
    }
}